package com.leetcode.common.utils;

import com.leetcode.common.model.ListNode;

/**
 * @author 覃国强
 * @date 2022-06-30 10:56
 */
public class ListNodeUtils {

  public static ListNode generateListNode(int[] nums) {
    ListNode dummy = new ListNode();
    ListNode tail = dummy;
    for (int num : nums) {
      tail.next = new ListNode(num);
      tail = tail.next;
    }
    return dummy.next;
  }

  public static void print(ListNode head) {
    while (head != null) {
      System.out.print(head.val + " ");
      head = head.next;
    }
    System.out.println();
  }

}
